package top.zhangjianyong.blog.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.zhangjianyong.blog.model.request.StsTokenRequest;
import top.zhangjianyong.blog.model.response.StsTokenResponse;
import top.zhangjianyong.blog.service.StsService;

/**
 * STS 控制器
 * 
 * @author zhangjianyong
 * @since 2024-01-01
 */
@Slf4j
@RestController
@RequestMapping("/api/sts")
public class StsController {
    
    @Autowired
    private StsService stsService;
    
    /**
     * 获取STS临时凭证
     * 
     * @param request STS Token请求参数
     * @return STS Token响应
     */
    @PostMapping("/token")
    public StsTokenResponse getStsToken(@RequestBody StsTokenRequest request) {
        log.info("收到STS Token请求，用户ID: {}, 操作类型: {}", request.getUserId(), request.getOperation());
        return stsService.getStsToken(request);
    }
    
    /**
     * 验证STS Token有效性
     * 
     * @param accessKeyId 访问密钥ID
     * @param securityToken 安全令牌
     * @return 是否有效
     */
    @GetMapping("/validate")
    public boolean validateToken(@RequestParam String accessKeyId, 
                               @RequestParam String securityToken) {
        log.info("验证STS Token，accessKeyId: {}", accessKeyId);
        return stsService.validateToken(accessKeyId, securityToken);
    }
    
    /**
     * 刷新STS Token
     * 
     * @param request STS Token请求参数
     * @return STS Token响应
     */
    @PostMapping("/refresh")
    public StsTokenResponse refreshToken(@RequestBody StsTokenRequest request) {
        log.info("刷新STS Token，用户ID: {}", request.getUserId());
        return stsService.refreshToken(request);
    }
} 